﻿
using Dapper;
using HBase; 
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace hCommand
{
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：Component                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2020/9/2 11:28:16                        
   *└────────────────────────────────────────────────┘
   **/
    public class ContinueInEngine<CS> : AbsTaskEngine where CS : AbsCoreStock {
        public long paramId;
        public int src;

        protected override TransRes Execute(IDbConnection connection ,IDbTransaction transaction) {
            CoreTaskParam ctp = connection.GetById<CoreTaskParam>(paramId ,transaction);
            List<CoreTaskParam> ctpList = connection.Query<CoreTaskParam>("select * from Core_Task_Param  where task_Id=@taskId" ,ctp ,transaction).ToList();
            foreach( CoreTaskParam p in ctpList ) {
                if( p.status < 4 ) {
                    return new TransRes("状态异常");
                }
            }
            CoreTask ct = connection.GetById<CoreTask>(ctp.taskId ,transaction);
            CS cs = connection.GetById<CS>(ct.stockId, transaction)  ;
            long stockId = cs.id;
            if( stockId == 0 ) {
                return new TransRes("stock 为空");
            }
            
            if(ct.bussType== (int)BussType.盘库) { 
                return new TransRes("待盘库不能继续入库");
            }
            
            CoreWhLoc loc = selectLoc(connection ,transaction , cs);
            if( loc == null ) {
                return new TransRes("货位获取异常");

            }
            long paramTaskId = moveCoreTaskParam(connection ,transaction ,null ,ct.id ,src ,( int ) loc.id ,"");
            UpdateStock(connection ,transaction ,cs.id ,StockStatus.移动中);
            UpdataWhLoc(connection ,transaction ,( int ) loc.id ,ct.goodDiff);

            return new TransRes();
        }

    }
}
